package com.medusa.aps.business.modules.modeling.controller;


import com.medusa.aps.business.model.pagination.Page;
import com.medusa.aps.business.modules.modeling.model.input.AuxiliaryDataDTO;
import com.medusa.aps.business.modules.modeling.model.input.AuxiliaryDataParam;
import com.medusa.aps.business.modules.modeling.mp.entity.AuxiliaryData;
import com.medusa.aps.business.modules.modeling.mp.service.AuxiliaryDataService;
import com.medusa.aps.business.common.model.resp.Result;
import com.medusa.aps.business.common.web.valid.group.Update;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Size;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 辅助资料控制层
 *
 * @author yuxh
 * @since 2023-08-14 17:37:39
 */
@Validated
@RestController
@RequestMapping("/auxiliaryData")
@Tag(name = "辅助资料控制层", description = "辅助资料控制层")
public class AuxiliaryDataController {
    /**
     * 服务对象
     */
    @Resource
    private AuxiliaryDataService auxiliaryDataService;

    /**
     * 分页查询辅助资源
     *
     * @param auxiliaryDataParam 辅助资源查询参数
     * @return 分页列表
     */
    @GetMapping("/pageAuxiliaryData")
    @Operation(summary = "分页查询辅助资源")
    public Result<Page<AuxiliaryData>> pageAuxiliaryData(AuxiliaryDataParam auxiliaryDataParam) {
        return Result.ok(auxiliaryDataService.pageAuxiliaryData(auxiliaryDataParam));
    }

    /**
     * 分页查询辅助资源
     *
     * @param auxiliaryDataParam 辅助资源查询参数
     * @return 分页列表
     */
    @GetMapping("/listAuxiliaryData")
    @Operation(summary = "分页查询辅助资源")
    public Result<Page<AuxiliaryData>> listAuxiliaryData(AuxiliaryDataParam auxiliaryDataParam) {
        return Result.ok(auxiliaryDataService.listAuxiliaryData(auxiliaryDataParam));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/selectById")
    @Operation(summary = "通过主键查询单条数据")
    public Result<AuxiliaryData> selectById(@RequestParam("id") Integer id) {
        return Result.ok(auxiliaryDataService.getById(id));
    }

    /**
     * 批量新增辅助资源
     *
     * @param auxiliaryDataCreates 辅助资料数据
     */
    @PostMapping("/save")
    @Operation(summary = "批量新增辅助资源")
    public Result<Void> saveBatchAuxiliaryData(@RequestBody @Valid @Size(min = 1, max = 50) List<AuxiliaryDataDTO> auxiliaryDataCreates) {
        auxiliaryDataService.saveBatchAuxiliaryData(auxiliaryDataCreates);
        return Result.ok();
    }

    /**
     * 修改辅助资源
     *
     * @param auxiliaryDataDTO 辅助资料数据
     */
    @PutMapping("/update")
    @Operation(summary = "修改数据")
    public Result<Boolean> updateAuxiliaryData(@RequestBody @Validated(Update.class) AuxiliaryDataDTO auxiliaryDataDTO) {
        auxiliaryDataService.updateAuxiliaryData(auxiliaryDataDTO);
        return Result.ok();
    }

    /**
     * 批量删除辅助资源
     *
     * @param ids id集合
     */
    @DeleteMapping("/delete")
    @Operation(summary = "删除数据")
    public Result<Void> deleteBatch(@RequestBody List<Integer> ids) {
        auxiliaryDataService.deleteBatch(ids);
        return Result.ok();
    }
}

